local ratio = {
    config = {
        f1 = {  -- 连击系数
            {1, 2, 3, 10,},
            {0.9, 0.9, 1, 1, 1.1,},
        },
        f2 = {  -- 输赢系数
            {-5000, -10000, -100000},
            {1, 1.1, 1.15, 1.2,},
        },
        f3 = {  -- 库存系数
            {-100000, 0, 100000, 500000},
            {0.8, 0.9, 0.95, 1, 1.1,},
        },
        f4 = {  -- 倍率系数
            1, 1, 1, 1, 1,
        },
    },
}

ratio['f1'] = function(val, config)
    config = config or ratio.config
    local f = config.f1
    -- if val > #f then return f[#f] end
    -- return f[val]
    if val >= f[1][#f[1]] then return f[2][#f[2]] end
    if val < f[1][1] then return f[2][1] end
    for i = 1, #f[1] - 1 do
        if f[1][i + 1] and f[2][i + 1] then
            if val >= f[1][i] and val < f[1][i + 1] then
                return f[2][i]
            end 
        end
    end
    print("----------- f1 should not reach here !!! -----------")
    return f[2][1]
end

ratio['f2'] = function(val, config)
    config = config or ratio.config
    local f = config.f2
    if val > f[1][1] then return f[2][1] end
    if val <= f[1][#f[1]] then return f[2][#f[2]] end
    for i = 1, #f[1] - 1 do
        if f[1][i + 1] and f[2][i + 1] then
            if val > f[1][i + 1] and val <= f[1][i] then
                return f[2][i + 1]
            end 
        end
    end
    print("----------- f2 should not reach here !!! -----------")
    return f[2][1]
end

ratio['f3'] = function(val, config)
    config = config or ratio.config
    local f = config.f3
    if val >= f[1][#f[1]] then return f[2][#f[2]] end
    if val < f[1][1] then return f[2][1] end
    for i = 1, #f[1] - 1 do
        if f[1][i + 1] and f[2][i + 1] then
            if val >= f[1][i] and val < f[1][i + 1] then
                return f[2][i + 1]
            end 
        end
    end
    print("----------- f3 should not reach here !!! -----------")
    return f[2][1]
end

ratio['f4'] = function(val, config)
    config = config or ratio.config
    local f = config.f4
    if val > #f then return f[#f] end
    return f[val]
end

return ratio